﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using TyMES.Model.Record;


namespace TyMES.ViewModel.Record.TighteningDataVMs
{
    public partial class TighteningDataListVM : BasePagedListVM<TighteningData_View, TighteningDataSearcher>
    {

        protected override IEnumerable<IGridColumn<TighteningData_View>> InitGridHeader()
        {
            return new List<GridColumn<TighteningData_View>>{
                this.MakeGridHeader(x => x.TID),
                this.MakeGridHeader(x => x.toolSerialNum),
                this.MakeGridHeader(x => x.tighteningID),
                this.MakeGridHeader(x => x.tool_id),
                this.MakeGridHeader(x => x.sn),
                this.MakeGridHeader(x => x.project_name),
                this.MakeGridHeader(x => x.torque),
                this.MakeGridHeader(x => x.angle),
                this.MakeGridHeader(x => x.tightening_status),
                this.MakeGridHeader(x => x.rawdata_time),
                this.MakeGridHeader(x => x.screw_id),
                this.MakeGridHeader(x => x.PointNum),
                this.MakeGridHeader(x => x.angle_offset),
                this.MakeGridHeader(x => x.ArrTorque),
                this.MakeGridHeader(x => x.upload_status),
                this.MakeGridHeader(x => x.upload_time),
                this.MakeGridHeader(x => x.filed1),
                this.MakeGridHeader(x => x.filed2),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<TighteningData_View> GetSearchQuery()
        {
            var query = DC.Set<TighteningData>()
                .CheckEqual(Searcher.TID, x=>x.TID)
                .CheckContain(Searcher.toolSerialNum, x=>x.toolSerialNum)
                .CheckEqual(Searcher.tighteningID, x=>x.tighteningID)
                .CheckEqual(Searcher.tool_id, x=>x.tool_id)
                .CheckContain(Searcher.sn, x=>x.sn)
                .CheckContain(Searcher.project_name, x=>x.project_name)
                .CheckContain(Searcher.torque, x=>x.torque)
                .CheckContain(Searcher.upload_status, x=>x.upload_status)
                .CheckContain(Searcher.upload_time, x=>x.upload_time)
                .CheckContain(Searcher.filed1, x=>x.filed1)
                .CheckContain(Searcher.filed2, x=>x.filed2)
                .Select(x => new TighteningData_View
                {
				    ID = x.ID,
                    TID = x.TID,
                    toolSerialNum = x.toolSerialNum,
                    tighteningID = x.tighteningID,
                    tool_id = x.tool_id,
                    sn = x.sn,
                    project_name = x.project_name,
                    torque = x.torque,
                    angle = x.angle,
                    tightening_status = x.tightening_status,
                    rawdata_time = x.rawdata_time,
                    screw_id = x.screw_id,
                    PointNum = x.PointNum,
                    angle_offset = x.angle_offset,
                    ArrTorque = x.ArrTorque,
                    upload_status = x.upload_status,
                    upload_time = x.upload_time,
                    filed1 = x.filed1,
                    filed2 = x.filed2,
                })
                . OrderByDescending(x => x.ID);
            return query;
        }

    }

    public class TighteningData_View : TighteningData{

    }
}
